package com.ly.lypopupwindowdemo.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.TextView;

import com.ly.lypopupwindowdemo.R;
import com.ly.lypopupwindowdemo.adapter.SingleAdapter;
import com.ly.lypopupwindowdemo.bean.SingleBean;

import java.util.ArrayList;
import java.util.List;

public class SingleActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    SingleAdapter adapter;
    private List<SingleBean> lists = new ArrayList<>();

    TextView round2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_single_or_multi);

        round2 = (TextView) findViewById(R.id.notifyItem);
        initData();
        recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

        //ScrollView嵌套RecyclerView的时候，因为都是滑动控件，所以滑动的时候会有卡顿的感觉
//        //解决这个问题可以重写LayoutManager，禁止掉RecyelrView的滑动
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false){
//            @Override
//            public boolean canScrollVertically() {
//                return false;
//            }
//        };
//        recyclerView.setLayoutManager(linearLayoutManager);

        //方法二，也可以解决滑动卡顿问题
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setSmoothScrollbarEnabled(true);
        layoutManager.setAutoMeasureEnabled(true);

        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        recyclerView.setNestedScrollingEnabled(false);

        //recyclerView.setLayoutManager(new LinearLayoutManager(this));

        adapter = new SingleAdapter(lists);
        recyclerView.setAdapter(adapter);
    }

    private void initData() {

        SingleBean bean1 = new SingleBean(true, "送别", "朴树");
        SingleBean bean2 = new SingleBean(false, "印第安老斑鹫", "周杰伦");
        SingleBean bean3 = new SingleBean(false, "一个像夏天一个像秋天", "范玮琪");
        SingleBean bean4 = new SingleBean(false, "我的梦", "张靓颖");
        SingleBean bean5 = new SingleBean(false, "浮夸", "陈奕迅");
        SingleBean bean6 = new SingleBean(false, "其实都没有", "杨宗纬");
        SingleBean bean7 = new SingleBean(false, "全世界谁倾听你", "林宥嘉");
        SingleBean bean8 = new SingleBean(false, "Look What You Made Me Do", "Taylar Swife");
        SingleBean bean9 = new SingleBean(false, "晴天", "周杰伦");
        SingleBean bean10 = new SingleBean(false, "七里香", "周杰伦");
        SingleBean bean11 = new SingleBean(false, "稻香", "周杰伦");
        SingleBean bean12 = new SingleBean(false, "听妈妈的话", "周杰伦");

        lists.add(bean1);
        lists.add(bean2);
        lists.add(bean3);
        lists.add(bean4);
        lists.add(bean5);
        lists.add(bean6);
        lists.add(bean7);
        lists.add(bean8);
        lists.add(bean9);
        lists.add(bean10);
        lists.add(bean11);
        lists.add(bean12);

    }

    public void round2(View v) {
        startActivity(new Intent(this, SingleActivity2.class));
    }

    public void round3(View v) {
        startActivity(new Intent(this, SingleActivity3.class));
    }
}
